//
//  CYStatus.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/8.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CYStatus: NSObject {
    
    var id: Int64 = 0
    
    var text: String?
    
    var created_at: String?
    
    var user: CYUser?
    
    var source: String?
    
    var reposta_count: Int = 0
    
    var comments_count: Int = 0
    
    var attitudes_count: Int = 0
    
    var retweeted_status: CYStatus?
    
    var pic_urls: [CYStatusPictureInfo]?
    
    init(dict:[String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            guard let v = value as? [String: AnyObject] else {
                return
            }
                user = CYUser(dict: v)
        
        }else if key == "retweeted_status" {
        
            guard let v = value as? [String :AnyObject] else {
                return
            }
                retweeted_status = CYStatus(dict: v)
            
        }else if key == "pic_urls" {
            guard let values = value as? [[String: AnyObject]] else {
                return
            }
            // 定义临时数组,以记录字典转模型的结果
            var tempArray = [CYStatusPictureInfo]()
            for v in values {
                // 字典转模型
                let pictureInfo = CYStatusPictureInfo(dict: v)
                tempArray.append(pictureInfo)
            }
            self.pic_urls = tempArray
        }else {
            super.setValue(value, forKey: key)
        }
        
    }
}
